<?php
session_start();
$user = isset($_SESSION["user"])?$_SESSION["user"]:null;

if(!$user){
    echo "未登录，请先去<a href='login.html'>登录</a>";
}else{
    //$id
    $title = $_POST["Title"];
    $content = $_POST["Content"];
    $createTime = (new DateTime())->format('Y-m-d H:i:s');
    $updateTime = $createTime;
    $authorId = $user["id"];
    $authorName = $user["Username"];

    $sql = "INSERT INTO `article` (`Title`,`Content`,`CreateTime`,`UpdateTime`,`AuthorId`,`AuthorName`)
    VALUES ('$title','$content','$createTime','$updateTime','$authorId','$authorName')";
    echo $sql;
    $conn = new mysqli("localhost",'root','',"myblog");
    $conn ->query($sql);
    if($conn->error) echo $conn->error;
    else echo "新添文章成功！";
}   

 
?>